package com.seecen.controller;


import com.seecen.pojo.entity.User;
import com.seecen.service.UserService;
import com.seecen.utils.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("/user")
@CrossOrigin
public class UserController {
    @Autowired
    private UserService userService;
    //登录接口
    @PostMapping("login")
    public Result login(@RequestBody User user){
        Result ret =  userService.login(user);
        log.info("ret ====> {}",ret);
        return ret;
    }
    //获取用户信息接口
    @GetMapping("getUser")
    public Result getUser(@RequestHeader String token){
        Result ret = userService.getUser(token);
        return ret;
    }
    //注册接口
    @PostMapping("/register")
    public Result register(@RequestBody User user){
        return userService.register(user);
    }
    // 直接重置密码接口
    @PostMapping("resp")
    public Result directResetPwd(
            @RequestParam String username,
            @RequestParam String newPassword
    ) {
        return userService.directResetPassword(username, newPassword);
    }
}
